﻿using SimpleESBCore.Common;
using SimpleESBCore.Implement.Serializer;
using SimpleESBCore.Interfaces;
using SimpleESBServer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinEsbServer
{
    public partial class frmServer : Form
    {
        IServer server;
        public frmServer()
        {
            InitializeComponent();
        }

        private void frmServer_Load(object sender, EventArgs e)
        {
            ServerOption serverOption = new ServerOption();
            serverOption.IPAddress = IPAddress.Parse("127.0.0.1");
            serverOption.HeartPort = 9000;
            serverOption.DataPort = 9001;
            serverOption.ServerName = "EsbServer";
            ILog log = new WinLog(txtMessage);
            ISerialization serialization = new JSONSerializer();
            server = new EsbServer(serverOption, log, serialization);
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            btnRestart.Enabled = true;
            btnStart.Enabled = false;
            btnStop.Enabled = true;
            server.Start();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            btnRestart.Enabled = false;
            btnStart.Enabled = true;
            btnStop.Enabled = false;
            server.Stop();
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            btnRestart.Enabled = false;
            btnStart.Enabled = false;
            btnStop.Enabled = true;
            //重启服务就是先关闭服务再启动服务即可
            server.Stop();
            server.Start();
        }
    }
}
